#pragma once 
#include <iostream>
#include <functional>
#include <unordered_map>
#include <cstdlib>
#include <time.h>

using task_t = std::function<void()>;
static int TaskNumbers = 0;

void Download(){
    std::cout << getpid()<< ",正在执行下载任务" << std::endl;
}
void Print(){
    std::cout << getpid()<< ",正在执行打印任务" << std::endl;
}
void Register(){
    std::cout << getpid()<< ",正在执行注册任务" << std::endl;
}

class TaskManager 
{
public:
    TaskManager()
    {
        srand(time(nullptr));
        _TaskList[TaskNumbers++] = Download;
        _TaskList[TaskNumbers++] = Print;
        _TaskList[TaskNumbers++] = Register;
    }
    int SelectTask(){
        return (rand() % TaskNumbers);
    }
    void Excute(int task)
    {
        if (_TaskList.find(task) == _TaskList.end()) return;
        _TaskList[task]();
    }
    ~TaskManager(){}
private:
    std::unordered_map<int,task_t> _TaskList;
};

TaskManager tm;